package com.yonyou.pmclouds.offline.service.rmiimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.offline.entity.OffLineInvocationContext;
import com.yonyou.pmclouds.offline.rmiitf.IOffLineDataDownloadService;
import com.yonyou.pmclouds.offline.rmiitf.IOffLineDataQueryService;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 离线数据下载服务类
 */
@Service(version = ApplicationConsts.APPLICATION_VERSION, interfaceClass = IOffLineDataDownloadService.class, timeout = 10000)
public class OffLineDataDownloadServiceImpl implements IOffLineDataDownloadService {

    private Map<String, IOffLineDataQueryService> constructorMap = new ConcurrentHashMap<>();


    @Override
    public Map<String, Object> queryOffLineData(OffLineInvocationContext invocationContext) throws BusinessException {
        Map<String, Object> offLineDataMap = new HashMap<>();
        for(Map.Entry<String, IOffLineDataQueryService> entry : constructorMap.entrySet()){
            Object offLineData = entry.getValue().queryOffLineData(invocationContext);
            offLineDataMap.put(entry.getKey(), offLineData);
        }

        return offLineDataMap;
    }

    @Override
    public void addService(String beanName, IOffLineDataQueryService offLineDataQueryService){
        constructorMap.put(beanName, offLineDataQueryService);
    }
}
